#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e7+5;
typedef int LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
int l,r;
int prime[maxn],f[maxn],v[maxn],cnt;
bool vis[maxn];
int ans[maxn];
void Euler(){
    f[1]=1;
    for(LL i=2;i<=r;i++){
        if(!vis[i]){
            prime[++cnt]=i;
            f[i]=v[i]=i+1;
            vis[i]=1;
        }
        for(LL j=1;j<=cnt&&prime[j]<=r/i;j++){
            vis[i*prime[j]]=1;
            if(i%prime[j]==0){
                v[i*prime[j]]=v[i]*prime[j]+1;
                f[i*prime[j]]=f[i]/v[i]*v[i*prime[j]];
                break;
            }
            else{
                v[i*prime[j]]=prime[j]+1;
                f[i*prime[j]]=f[i]*f[prime[j]];
            }
        }
    }
}
int main(){
    memset(ans,-1,sizeof(ans));
    r=1e7+5;
    Euler();
    for(LL i=1;i<=r;i++){
        if(f[i]>1e7) continue;
        if(ans[f[i]]==-1){
            ans[f[i]]=i;
        }
    }
    int t;scanf("%d",&t);
    while(t--){
        int x;scanf("%d",&x);
        printf("%d\n",ans[x]);
    }
    return 0;
}
